// 
// $Rev:: 18            $:  Revision of last commit
// $Author:: rvhaverm@g#$:  Author of last commit
// $Date:: 2010-07-25 1#$:  Date of last commit
// 
package agents.listeners;

import com.ibm.aglet.event.CloneEvent;
import com.ibm.aglet.event.MobilityEvent;
import com.ibm.aglet.event.PersistencyEvent;

import agents.core.Components;
import agents.interfaces.IAgent;
import agents.interfaces.IAgentEventListener;
import agents.interfaces.IMessage;

public class ConsoleAgentEventListener implements IAgentEventListener
{

    @Override
    public void onArrival(MobilityEvent event)
    {
	System.out.print("arrived");
	System.out.println();
    }

    @Override
    public void onDispatching(MobilityEvent event)
    {
	System.out.print("dispatching");
	System.out.println();
    }

    @Override
    public void onReverting(MobilityEvent event)
    {
	System.out.print("reverting");
	System.out.println();
    }

    @Override
    public void onActivation(PersistencyEvent event)
    {
	System.out.print("activating");
	System.out.println();
    }

    @Override
    public void onDeactivating(PersistencyEvent event)
    {
	System.out.print("deactivating");
	System.out.println();
    }

    @Override
    public void onClone(CloneEvent event)
    {
	System.out.print("clone");
	System.out.println();
    }

    @Override
    public void onCloned(CloneEvent event)
    {
	System.out.print("cloned");
	System.out.println();
    }

    @Override
    public void onCloning(CloneEvent event)
    {
	System.out.print("cloning");
	System.out.println();
    }

    @Override
    public void onCreation(IAgent agent, Object init)
    {
	System.out.print(agent.getClass().getName().toUpperCase());
	System.out.print(" was spawned at host '");
	System.out.print(agent.getHost());
	System.out.println("'");
    }

    @Override
    public void onDisposing(IAgent agent)
    {
	System.out.print(agent.getClass().getName().toUpperCase());
	System.out.print(" is being killed at host '");
	System.out.print(agent.getHost());
	System.out.println("'");
    }

    @Override
    public boolean onMessageReceived(IAgent agent, IMessage msg)
    {
	System.out.print(agent.getClass().getName().toUpperCase());
	System.out.print(": received message '"); 
	System.out.print(msg.getClass().getName().toUpperCase());
	System.out.println("'");
	return true;
    }

}
